# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Ebubekir KARUL <ebubekirkarul@yandex.com>
# Contributor: s1gma,shirokuro

pkgbase=scapy
pkgname=('scapy' 'python-scapy')
pkgver=2.5.0
pkgrel=3
pkgdesc='Powerful interactive packet manipulation program written in Python'
url='http://www.secdev.org/projects/scapy/'
arch=('any')
license=('GPL2')
makedepends=(
  tcpdump
  python-build
  python-installer
  python-setuptools
  python-wheel
  python-sphinx
)
checkdepends=('python-cryptography' 'python-pyx' 'python-matplotlib'
              'graphviz' 'sox')
source=(https://github.com/secdev/scapy/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('97c3f6c9258eeaa609e3ccab62531670b425713dd17c0415f512201c2b8cc82e')
sha512sums=('4e5cacff0bbf6fd991ea24f4680049d042082fae4b349c8082078e6f01b38c09bb5c8276bfba15d4a88a1eb5af92c505848ec98556b10eecbd803f134a5b244a')

build() {
  cd ${pkgbase}-${pkgver}
  python -m build --wheel --no-isolation
}

check() {
  # Run only main tests, without network access
  cd ${pkgbase}-${pkgver}/test
  ./run_tests -K netaccess -F
}

package_scapy() {
  depends=('python' 'python-scapy')
  pkgdesc+=' (tools)'
  cd ${pkgbase}-${pkgver}
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -d "${pkgdir}/usr/share/doc"
  ln -sf /usr/share/doc/python-scapy "${pkgdir}/usr/share/doc/${pkgname}"
  rm -r "${pkgdir}/usr/lib"
}

package_python-scapy() {
  pkgdesc+=' (library)'
  depends=('tcpdump' 'python')
  # TODO: clenup optdeps
  optdepends=('python-cryptography: WEP, IPsec and SSL/TLS support'
              'python-pyx: psdump() and pdfdump() functions'
              'python-matplotlib: plotting support'
              'graphviz: conversations() method support'
              'sox: for VOIP support')
  cd ${pkgbase}-${pkgver}
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm 644 doc/scapy/*.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  rm -r "${pkgdir}"{/usr/bin,/usr/share/man}
  rm -r "${pkgdir}"/usr/lib/python*/site-packages/test/
}

# vim: ts=2 sw=2 et:
